//
//  NYPhoneCondition.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/11/3.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "NYPhoneCondition.h"
#import "NBPhoneNumberUtil.h"
#import "NBPhoneNumber.h"

@interface NYPhoneCondition ()
@property(nonatomic, strong) NBPhoneNumberUtil *phoneNumUtil;
@end

@implementation NYPhoneCondition
- (BOOL)check:(NSString *)string
{
        self.currentCheckString = string.copy;
        NSError *error = nil;
        BOOL res = NO;

//        NSString *addCountryCodeNum = [NSString stringWithFormat:@"+%@%@",NYUserManager.country_code,string];
        NSString *addCountryCodeNum = [NSString stringWithFormat:@"+%@%@",@"86",string];
        NBPhoneNumber *phoneNumber = [self.phoneNumUtil parseWithPhoneCarrierRegion:addCountryCodeNum error:&error];
        res = [self.phoneNumUtil isValidNumber:phoneNumber];
        
        return res;
}
- (NSString *)violationResultString
{
        return self.currentCheckString;
}
- (NBPhoneNumberUtil *)phoneNumUtil
{
        if (!_phoneNumUtil) {
                _phoneNumUtil = [[NBPhoneNumberUtil alloc] init];
        }
        return _phoneNumUtil;
}

#pragma mark - Allow violation

- (BOOL)shouldAllowViolation
{
        return YES;
}

@end
